package com.weipai.education.controller;

import com.weipai.education.model.InventoryIn;
import com.weipai.education.model.api.Response;
import com.weipai.education.service.InventoryService;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;

/**
 * @Author: 曹朋飞
 * @Date: 2018/12/13 15:06
 * 
 * 库存控制器
 */
@RestController
@Validated
public class InventoryController {
    
    @Autowired
    private InventoryService inventoryService;

    /**
     * 库存列表
     * @param page
     * @param size
     * @param spuNumber
     * @param key
     * @param type : type为null表示查询总部的库存，type==own表示查询自己的库存，市级经销商传自己的id
     * @return
     */
    @RequestMapping(value = "/inventory/list", method = RequestMethod.GET)
    public Response list(@NotNull(message = "page不能为空") @RequestParam(value = "page") Integer page,
                         @NotNull(message = "size不能我空") @RequestParam(value = "size") Integer size,
                         @RequestParam(value = "spuNumber", required = false) String spuNumber,
                         @RequestParam(value = "key", required = false) String key,
                         @RequestParam(value = "type", required = false) String type){
        return inventoryService.list(page, size, spuNumber, key, type);
    }

    /**
     * 生成商品条形码
     * @return
     */
    @RequestMapping(value = "/inventory/createGoodsBarCode", method = RequestMethod.GET)
    public Response createGoodsBarCode(@NotNull(message = "生成数量不能为空") Integer number,
                                       @NotNull(message = "产品id不能为空") Integer productId){
        return inventoryService.createGoodsBarCode(number, productId);
    }

    /**
     * 出库订单分页查询
     * @param page
     * @param size
     * @param goodsBarCode
     * @param spuNumber
     * @param startTime
     * @param endTime
     * @param type:0查询总部的全部出库单，1查询自己的出库单
     * @return
     */
    @RequestMapping(value = "/inventory/inventoryOutList", method = RequestMethod.GET)
    public Response inventoryOutList(@NotNull(message = "page不能为空") @RequestParam(value = "page") Integer page,
                                     @NotNull(message = "size不能为空") @RequestParam(value = "size") Integer size,
                                     @RequestParam(value = "goodsBarCode", required = false) String goodsBarCode,
                                     @RequestParam(value = "spuNumber", required = false) String spuNumber,
                                     @RequestParam(value = "startTime", required = false) String startTime,
                                     @RequestParam(value = "endTime", required = false) String endTime,
                                     @RequestParam(value = "type", defaultValue = "0") String type){
        return inventoryService.inventoryOutList(page, size, goodsBarCode, spuNumber, startTime, endTime, type);
    }

    /**
     * 入库订单分页查询
     * @param page
     * @param size
     * @param goodsBarCode
     * @param spuNumber
     * @param startTime
     * @param endTime
     * @param type:0查询总部的全部出库单，1查询自己的出库单
     * @return
     */
    @RequestMapping(value = "/inventory/inventoryInList", method = RequestMethod.GET)
    public Response inventoryInList(@NotNull(message = "page不能为空") @RequestParam(value = "page") Integer page,
                                    @NotNull(message = "size不能为空") @RequestParam(value = "size") Integer size,
                                     @RequestParam(value = "goodsBarCode", required = false) String goodsBarCode,
                                     @RequestParam(value = "spuNumber", required = false) String spuNumber,
                                     @RequestParam(value = "startTime", required = false) String startTime,
                                     @RequestParam(value = "endTime", required = false) String endTime,
                                    @RequestParam(value = "type", defaultValue = "0") String type){
        return inventoryService.inventoryInList(page, size, goodsBarCode, spuNumber, startTime, endTime, type);
    }

    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
}
